<?php
$posicao = (!isset($posicao) ? 1 : $posicao);
$div['class'] = (!isset($div['class']) ? '' : $div['class']);
$options = (!isset($options) ? array() : $options);

$_id = md5(uniqid() . time());

$_url = array('plugin' => 'banners', 'controller' => 'banners_has_paginas', 'action' => 'index');
$_named['named'] = array();
if (isset($this->request->params['pass'][0]) AND $this->request->params['plugin'] == 'paginas') {
    $_named['named']['BannersHasPagina.paginas_id'] = $this->request->params['pass'][0];
} else {
    $_named['named']['Banner.exibir_no_conteudo'] = 1;
}
$_named['named']['Banner.status'] = 1;
if ($posicao) {
    $_named['named']['Banner.banners_posicao_id'] = $posicao;
}

$_url['sort'] = 'created';
$_url['direction'] = 'desc';

$_banner = $this->requestAction($_url, $_named);
if (count($_banner) > 0) {
    ?>  
    <div id="carousel-<?php echo $_id; ?>" class="carousel slide wow fadeIn" data-ride="carousel">
        <div class="carousel-inner">
            <?php
            $_active = 'active';
            foreach ($_banner as $key => $value) {
                if ($value['Banner']['url']) {
                    $options['url'] = $value['Banner']['url'];
                }
                if ($value['Banner']['nome']) {
                    $options['alt'] = $value['Banner']['nome'];
                    $options['title'] = $value['Banner']['nome'];
                }
                if ($value['Banner']['target']) {
                    $options['target'] = $value['Banner']['target'];
                }
                ?>
                <div class="item <?php echo $_active; ?>">
                    <?php echo $this->Midia->get($value['Banner']['midia_id'], $options); ?>
                    <div class="carousel-caption">
                        <?php echo $value['Banner']['nome']; ?>
                    </div>
                </div>
                <?php
                $_active = '';
            }
            ?>
        </div>
        <a class="left carousel-control" href="#carousel-<?php echo $_id; ?>" role="button" data-slide="prev">
            <span class="glyphicon glyphicon-chevron-left"></span>
        </a>
        <a class="right carousel-control" href="#carousel-<?php echo $_id; ?>" role="button" data-slide="next">
            <span class="glyphicon glyphicon-chevron-right"></span>
        </a>
    </div>
    <?php
}
?>